<?php

/**
 * Description of numberElement
 *
 * @author GILLES
 */
class Cab_View_Helper_NumberElement extends Zend_View_Helper_FormElement {

    protected $html = '';

    public function numberElement($name, $value = null, $attribs = null) {

        $num = $cle = '';

        $helper = new Zend_View_Helper_FormText();
        $helper->setView($this->view);

        if (isset($value) && !is_array($value) && strlen($value) == 15) {
            $num = str_split($value, 13);
            $value = array('num' => $num[0], 'cle' => $num[1]);
        } else {
            $value = array('num' => '', 'cle' => '');
        }

        if (is_array($value)) {
            $num = (isset($value['num'])) ? $value['num'] : '';
            $cle = (isset($value['cle'])) ? $value['cle'] : '';
        }

        $this->html .= $helper->formText($name . '[num]', $num, array(
            'Size' => '13',
            'maxlength' => '13',
            'placeholder' => '0112233456777',
            'style' => 'width:8em;text-align:center;'));

        $this->html .= "<label class='required' style='float:none; margin-left:4px;' >Clé</label>";

        $this->html .= $helper->formText($name . '[cle]', $cle, array(
            'Size' => '2',
            'maxlength' => '2',
            'placeholder' => '12',
            'style' => 'margin-left:4px;width:2em;text-align:center;'));
        return $this->html;
    }

}

